package com.guofen.service.sjq.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guofen.dao.SjqFlocculationProduceCheckMapper;
import com.guofen.pojo.ShljStorageBoxClean;
import com.guofen.pojo.SjqFlocculationProduceCheck;
import com.guofen.service.sjq.SjqFlocculationProduceCheckService;
import com.guofen.util.DateAndTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SjqFlocculationProduceCheckServiceImpl implements SjqFlocculationProduceCheckService {
    @Autowired
    private SjqFlocculationProduceCheckMapper sjqFlocculationProduceCheckMapper;

    @Override
    public boolean addOperationalForm(String equipment_name,String is_normal, String remarks, String operator) {
        //获取当前日期
        String date = DateAndTimeUtil.getDate();



        SjqFlocculationProduceCheck sjqFlocculationProduceCheck = new SjqFlocculationProduceCheck();
        sjqFlocculationProduceCheck.setDate(date);
        sjqFlocculationProduceCheck.setEquipmentName(equipment_name);
        sjqFlocculationProduceCheck.setIsNormal(is_normal);
        sjqFlocculationProduceCheck.setRemarks(remarks);
        sjqFlocculationProduceCheck.setOperator(operator);

        int result = sjqFlocculationProduceCheckMapper.insert(sjqFlocculationProduceCheck);
        if (result == 1)
            return true;
        else
            return false;
    }

    @Override
    public boolean addExaminationalForm(String id, String inspector, String remarks) {
        SjqFlocculationProduceCheck sjqFlocculationProduceCheck = new SjqFlocculationProduceCheck();
        sjqFlocculationProduceCheck.setId(Integer.parseInt(id));
        sjqFlocculationProduceCheck.setInspector(inspector);
        sjqFlocculationProduceCheck.setRemarks(remarks);
        int result = sjqFlocculationProduceCheckMapper.updateByPrimaryKeySelective(sjqFlocculationProduceCheck);
        if (result == 1)
            return true;
        else
            return false;
    }

    @Override
    public List<SjqFlocculationProduceCheck> findEquipList() {
        return sjqFlocculationProduceCheckMapper.findEquipList();
    }

    @Override
    public List<SjqFlocculationProduceCheck> findFaultEquipList() {
        return sjqFlocculationProduceCheckMapper.findFaultEquipList();
    }

    @Override
    public Map<String, Object> get(int pageSize, int currentPage) {
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(currentPage, pageSize);
        List<SjqFlocculationProduceCheck> list = sjqFlocculationProduceCheckMapper.selectAll();
        PageInfo pageRecord = new PageInfo(list);
        long sum = pageRecord.getTotal();
        list = pageRecord.getList();
        map.put("records",list);
        map.put("sum",sum);
        return map;
    }

    @Override
    public Map<String, Object> getByTime(int pageSize, int currentPage, long startTime, long endTime) {
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(currentPage, pageSize);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String startDate = dateFormat.format(new Date(startTime));
        String endDate = dateFormat.format(new Date(endTime));
        List<SjqFlocculationProduceCheck> list = sjqFlocculationProduceCheckMapper.selectByDate(startDate, endDate);
        PageInfo pageRecord = new PageInfo(list);
        long sum = pageRecord.getTotal();
        list = pageRecord.getList();
        map.put("records",list);
        map.put("sum",sum);
        return map;
    }

    @Override
    public int delete(int id) {
        return sjqFlocculationProduceCheckMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(SjqFlocculationProduceCheck record) {
        return sjqFlocculationProduceCheckMapper.updateByPrimaryKeySelective(record);
    }
}
